package com.xxxx.servlet;

import java.io.IOException;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

/*
 * 请求乱码问题
 * GET请求 			不会乱码
 * POST请求			会乱码,通过设置服务器解析编码的格式request.setCharacterEncoding("utf-8");
 * 乱码情况:
 * POST请求: 无论什么版本的服务器,post请求中文都会乱码,request.setCharacterEncoding("utf-8");				
 */



@WebServlet("/S2")
public class Servlet02请求乱码问题 extends HttpServlet {
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
			//设置请求的编码格式
			request.setCharacterEncoding("utf-8");
		
			//获取客户端传递的参数
			String uname = request.getParameter("uname");
			String upwd = request.getParameter("upwd");
			System.out.println("姓名: "+uname);
			System.out.println("密码: "+upwd);
	}
		
}
